package com.xiaoniu.forum.service.impl;

import com.alibaba.fastjson.JSON;
import com.xiaoniu.forum.renren.common.utils.R;
import com.xiaoniu.forum.service.WebSocketMessageService;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.websocket.Session;
import java.io.IOException;
import java.util.Map;

@Service
public class WebSocketMessageServiceImpl implements WebSocketMessageService {


    @Override
    public void sendMessageToMember(String memberId, String message, Map<String, Session> sessionMap) throws IOException {
        Session session = sessionMap.get(memberId);
        if (session == null) return;
        try {
            session.getBasicRemote().sendText(message);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
